package de.kardass.jsmatep.in.adjust;

import de.kardass.jsmatep.schema.jSmaTePImportConfig.RecordImportConfigType;

public class VariableLengthRecordAdjuster extends AbstractRecordAdjuster {

	public VariableLengthRecordAdjuster(RecordImportConfigType importConfig) {
		super(importConfig);
	}

	/* (non-Javadoc)
	 * @see de.kardass.jsmatep.in.adjust.RecordAdjuster#adjustRecordVsConfig(java.lang.String)
	 */
	public String adjustRecordVsConfig(String record) {
		// check whether adjustment required
		final String fillWith = getImportConfig().getType().getVariableLength().getFillWith();
		if (fillWith != null && fillWith.length() > 0) {
			final int requiredLength = getImportConfig().getType().getFixedLength().getRecordLength();
			if (record.length() < requiredLength) {
				final StringBuilder builder = new StringBuilder(record);
				while(builder.length() < requiredLength) {
					builder.append(fillWith);
				}
				record = builder.toString();
			}
		}
		return record;
	}

}
